/*
 * Description: defender action utilities.
 */
#ifndef DEFENDER_UTILS_H
#define DEFENDER_UTILS_H

#include <algorithm>
#include <functional>
#include <vector>
#include <unordered_map>
#include <Windows.h>
#include <atlbase.h>
#include <atlsafe.h>
#include <comutil.h>
#include <Wbemidl.h>
#include <tchar.h>
#include "log.h"

namespace PERF {

enum class ExclusionType {
    PATH = 0,
    PROCESS,
    EXTENSION,
};

enum class ExclusionCommand { ADD = 0, REMOVE };

class DefenderUtils {
public:
    static bool AddExclusionItem(const std::string &item, ExclusionType type = ExclusionType::PATH);
    static bool RemoveExclusionItem(const std::string &item, ExclusionType type = ExclusionType::PATH);
    static bool GetCurrentExclusionItems(std::vector<std::string> &items, ExclusionType type = ExclusionType::PATH);

private:
    static std::unordered_map<ExclusionType, std::wstring> EXCLUSION_TYPE_TO_COM_PARAM;
    static bool DefenderCommandInit(CComPtr<IWbemLocator> &pLocator, CComPtr<IWbemServices> &pServices);
    static bool DefenderCommandGetMethod(ExclusionCommand cmd, CComPtr<IWbemServices> pServices,
                                         CComPtr<IWbemClassObject> &pParamInstance, _bstr_t &methodName);
    static bool DefenderCommandExec(const std::string &exclusiveItem, CComPtr<IWbemServices> pServices,
                                    CComPtr<IWbemClassObject> pParamInstance, _bstr_t &methodName, ExclusionType type);
    static bool ReadExclusionItemsFromCComVariant(CComVariant &variant, std::vector<std::string> &items);
};
}  // namespace PERF
#endif